package com.naiterui.ehp.bs.doctor.vo;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import com.google.common.base.MoreObjects;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.utils.biz.NameUtil;
import com.naiterui.ehp.bp.utils.esign.ESignUtils;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 医生上传个人信息VO
 *
 * @author 王泽浩
 * @since 1.0.0
 */
@Data
@ApiModel(value = "DoctorParaRequestVO", description = "医生上传个人信息VO")
public class DoctorParaRequestVO implements java.io.Serializable {

    private static final long serialVersionUID = -7378530116632381831L;

    /**
     * 医生ID
     */
    @ApiModelProperty(value = "医生ID")
    private Long doctorId;

    /**
     * 城市ID
     */
    @ApiModelProperty(value = "城市ID")
    private Integer cityId;

    /**
     * 自定义科室名
     */
    @ApiModelProperty(value = "自定义科室名")
    private String customDepartment;

    /**
     * 科室id
     */
    @ApiModelProperty(value = "科室id")
    private Integer departmentId;

    /**
     * 性别
     */
    @ApiModelProperty(value = "性别")
    private Integer gender;

    /**
     * 医院id
     */
    @ApiModelProperty(value = "医院id")
    private Integer hospitalId;

    /**
     * 自定义医院名
     */
    @ApiModelProperty(value = "自定义医院名")
    private String hospitalName;

    /**
     * 姓名
     */
    @ApiModelProperty(value = "医生姓名")
    private String name;

    /**
     * 职级。0医师，1副主任医师，2主任医师，3主治医师，4主院医师
     */
    @ApiModelProperty(value = "职级。0医师，1副主任医师，2主任医师，3主治医师，4主院医师")
    private Integer titleId;

    /**
     * 联系电话
     */
    @ApiModelProperty(value = "联系电话")
    private String phone;

    /**
     * 专业与专长
     */
    @ApiModelProperty(value = "专业与专长")
    private String expertise;

    /**
     * 医生简介
     */
    @ApiModelProperty(value = "医生简介")
    private String introduction;

    /**
     * 签章图片地址
     */
    @ApiModelProperty(value = "签章图片地址")
    private String sealImgUrl;

    /**
     * 签章图片
     */
    @ApiModelProperty(value = "签章图片")
    private MultipartFile sealImg;

    /**
     * 电子邮箱
     */
    @ApiModelProperty(value = "电子邮箱")
    private String email;

    /**
     * 校验参数是否完整
     *
     * @throws BusinessException 参数不正确
     */
    public void validator() throws BusinessException {

        // 判断参数是否完整
        if (doctorId == null) {
            throw new BusinessException(ExceptionCodes.PARAM_ERROR);
        }

        if (StringUtils.isEmpty(name) || null == titleId || null == departmentId || null == hospitalId
            || (ESignUtils.isHandWriting() && (sealImg == null && StringUtils.isEmpty(sealImgUrl)))) {
            throw new BusinessException(ExceptionCodes.DOCTOR_NOT_COMPLETE);
        }

        if (StrUtil.length(name) > 20) {
            throw new BusinessException(ExceptionCodes.REGIST_NAME_ERROR, "姓名不能超过20字");
        }
        if (!NameUtil.verify(name)) {
            throw new BusinessException(ExceptionCodes.REGIST_NAME_ERROR, "姓名只支持中文字符");
        }

    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this).add("doctorId", doctorId).add("cityId", cityId).add("customDepartment", customDepartment)
                .add("departmentId", departmentId).add("gender", gender).add("hospitalId", hospitalId).add("hospitalName", hospitalName)
                .add("name", name).add("titleId", titleId).add("phone", phone).add("expertise", expertise).add("introduction", introduction)
                .toString();
    }
}
